package org.jhotdraw.app.action.file;

import java.net.URI;

import javax.swing.JOptionPane;

import org.jhotdraw.app.Application;
import org.jhotdraw.app.View;
import org.jhotdraw.draw.Drawing;
import org.jhotdraw.gui.URIChooser;
import org.jhotdraw.gui.Worker;
import org.jhotdraw.util.ResourceBundleUtil;

import stateDiagram.AnimationEngine;
import stateDiagram.StateDiagramView;

public class AnimateDrawingAction extends LoadFileAction {
	
	public final static String ID = "file.animateDrawing";

	public AnimateDrawingAction(Application app, View view) {
		super(app, view);
		ResourceBundleUtil labels = ResourceBundleUtil.getBundle("stateDiagram.Labels");
        labels.configureAction(this, ID);
	}
	
	public void loadViewFromURI(final View view, final URI uri, final URIChooser chooser) {
		final Drawing drawing = ((StateDiagramView) this.getActiveView()).getEditor().getActiveView().getDrawing();
		
		view.execute(new Worker() {
            @Override
            public Object construct() {
                boolean isWorking = true;
                AnimationEngine a = new AnimationEngine(uri, drawing);
                while (isWorking){
                	isWorking = a.animate();
                }
                a.end();
                JOptionPane.showMessageDialog(view.getComponent(),("Done!"));
                return null;
            }
        });
		
		
	}

}
